主题
从内存加载明文模型 - YoloLoadModelMemoryEx
函数简介
从内存加载明文主模型,可选 NCNN .param 与类别名表。
接口名称
YoloLoadModelMemoryExDLL 调用
long YoloLoadModelMemoryEx(long ola, long modelData, int modelSize, long ncnnParamData, int ncnnParamSize, long labelData, int labelSize, int modelType, int inferenceType, int inferenceDevice);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。 |
| modelData | 长整数型 | 主模型内存地址 |
| modelSize | 整数型 | 主模型字节数 |
| ncnnParamData | 长整数型 | NCNN .param 地址,无则 0 |
| ncnnParamSize | 整数型 | NCNN .param 长度 |
| labelData | 长整数型 | 类别名称表内存地址;无则 0。传原始文件字节,编码自动识别,见 类别名称表说明 |
| labelSize | 整数型 | 类别名称表字节长度(精确字节数,不含多余 \0);无则 0 |
| modelType | 整数型 | 模型类型 |
| inferenceType | 整数型 | 推理类型 |
| inferenceDevice | 整数型 | inferenceDevice:-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);csharp
using OLAPlug;
var ola = new OLAPlugServer();
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.YoloLoadModelMemoryEx(0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
YoloLoadModelMemoryEx(instance, 0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long YoloLoadModelMemoryEx(long ola, long modelData, int modelSize, long ncnnParamData, int ncnnParamSize, long labelData, int labelSize, int modelType, int inferenceType, int inferenceDevice);
long instance = CreateCOLAPlugInterFace();
YoloLoadModelMemoryEx(instance, 0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.YoloLoadModelMemoryEx(instance, 0, 0, "models/yolov8n.olam", "models/yolov8n.olam", 0, 0, 0, 0, 0)返回值
长整数型:模型句柄,失败返回 0。
注意事项
- 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
| 值 | 含义 |
|---|---|
| 0 | TensorRT Engine(.engine) |
| 1 | ONNX(.onnx) |
| 2 | NCNN(.bin + .param 双文件) |
| 值 | 含义 |
|---|---|
| 0 | Detect 目标检测 |
| 1 | Classify 图像分类 |
| 2 | Segment 实例分割 |
| 3 | Pose 姿态估计 |
| 4 | Obb 旋转框检测 |
inferenceDevice:-1表示 CPU;0及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。- 缓冲区不得为加密包格式。
- 推荐
labelBytes = File.ReadAllBytes("labels.txt"),labelSize = labelBytes.Length;支持\|分隔、多行及 UTF-8/GBK 等编码,见 类别名称表说明。
